package com.exigenservices.demenkov.model.dao.Impl;

import com.exigenservices.demenkov.model.dao.NewsDAO;
import com.exigenservices.demenkov.model.domain.News;
import org.springframework.stereotype.Repository;

import javax.persistence.Query;
import java.util.List;

/**
 * Implementation for NewsDAO
 *
 * @Author DemYura
 * @Date 24.11.11
 */
@Repository
public class NewsDAOImpl extends GenericDAOImpl<News, Long> implements NewsDAO {
    @SuppressWarnings("unchecked")
    public List<News> getAllNews() {
        return entityManager.createQuery("Select n from News n").getResultList();
    }

    @SuppressWarnings("unchecked")
    public List<News> getLatestNews(int count) {
        Query query = entityManager.createQuery("Select n from News n order by n.year desc,n.month desc,n.day desc,n.time desc");
        query.setMaxResults(count);
        return query.getResultList();
    }
}
